package com.cyz.admin.controller;

import com.cyz.common.validated.UpdateGroup;
import com.cyz.admin.service.AdService;
import com.cyz.common.utils.R;
import com.cyz.common.validated.AddGroup;
import com.cyz.common.dto.AdDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "管理端广告相关接口")
@RestController
@RequestMapping("/ad")
public class AdController {

    @Autowired
    private AdService adService;

    @PreAuthorize("@ps.hasPermission('contant:free:ad')")
    @ApiOperation(value = "查询免费课程页面广告信息")
    @GetMapping("/queryFreeAds")
    public R queryFreeAds(){
        return adService.queryFreeAds();
    }

    @PreAuthorize("@ps.hasPermission('contant:free:ad')")
    @ApiOperation(value = "删除免费课程页面广告信息")
    @DeleteMapping("/deleteFreeAds")
    public R deleteFreeAds(Integer[] ids){
        return adService.deleteFreeAds(ids);
    }

//    @ApiOperation(value = "删除付费课程页面广告信息")
//    @DeleteMapping("/deleteMoneyAds")
//    public R deleteMoneyAds(Integer[] ids){
//        return adService.deleteMoneyAds(ids);
//    }

    @PreAuthorize("@ps.hasPermission('contant:free:ad')")
    @ApiOperation(value = "增加免费课程页面广告信息")
    @PostMapping("/addFreeAd")
    public R addFreeAd(@Validated(AddGroup.class) @RequestBody AdDto adDto){
        return adService.addFreeAds(adDto);
    }

//    @ApiOperation(value = "增加付费课程页面广告信息")
//    @PostMapping("/addMoneyAd")
//    public R addMoneyAd(@Validated(AddGroup.class) @RequestBody AdDto adDto){
//        return adService.addMoneyAd(adDto);
//    }

    @PreAuthorize("@ps.hasPermission('contant:free:ad')")
    @ApiOperation(value = "更新免费课程页面广告信息")
    @PutMapping("/updateFreeAd")
    public R updateFreeAd(@Validated(UpdateGroup.class) @RequestBody AdDto adDto){
        return adService.updateFreeAd(adDto);
    }

//    @ApiOperation(value = "更新付费课程页面广告信息")
//    @PutMapping("/updateMoneyAd")
//    public R updateMoneyAd(@Validated(UpdateGroup.class) @RequestBody AdDto adDto){
//        return adService.updateMoneyAd(adDto);
//    }

}
